//
//  XOWMRegisterView.m
//  XOWMSDK
//
//  Created by skyline on 2018/7/26.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "XOWMRegisterView.h"
@interface XOWMRegisterView()<YJDNameRegisterViewDelegate, YJDPhoneRegisterViewDelegate>
@property (nonatomic, strong) UIScrollView *scrollView;
@end
@implementation XOWMRegisterView

- (XOWMButton *)nameRegisterBtn
{
    if (!_nameRegisterBtn)
    {
        _nameRegisterBtn = [[XOWMButton alloc] init];
        _nameRegisterBtn.height = TITLE_HEIGHT;
        _nameRegisterBtn.style = YJDButtonTitleStyleCameo;
        [_nameRegisterBtn addTarget:self action:@selector(yjd_actionForNameRegisterButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_nameRegisterBtn];
        _nameRegisterBtn.c_centerY.equal(self.backBtn);
        if (VERSION_1_2_0_LATER)
            _nameRegisterBtn.c_right.equal(self.c_centerX).with.coffset(-GAP / 2.0);
        else
            _nameRegisterBtn.c_centerX.equal(self.c_centerX);
    }
    return _nameRegisterBtn;
}

- (XOWMButton *)phoneRegisterBtn
{
    if (!_phoneRegisterBtn)
    {
        _phoneRegisterBtn = [[XOWMButton alloc] init];
        _phoneRegisterBtn.height = TITLE_HEIGHT;
        _phoneRegisterBtn.style = YJDButtonTitleStyleCameo;
        [_phoneRegisterBtn addTarget:self action:@selector(yjd_actionForPhoneRegisterButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_phoneRegisterBtn];
        _phoneRegisterBtn.c_left.equal(self.c_centerX);
        _phoneRegisterBtn.c_centerY.equal(self.backBtn);
    }
    return _phoneRegisterBtn;
}

- (UIScrollView *)scrollView
{
    if (!_scrollView)
    {
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.scrollEnabled = NO;
        _scrollView.contentSize = CGSizeMake(self.bounds.size.width * 2, self.bounds.size.height - BUTTONHEIGHT - LINE_HEIGHT);
        [self addSubview:_scrollView];
        _scrollView.c_edges.equal(UIEdgeInsetsMake(BUTTONHEIGHT + LINE_HEIGHT, 0, 0, 0));
    }
    return _scrollView;
}

- (XOWMNameRegisterView *)nameRegisterView
{
    if (!_nameRegisterView)
    {
        _nameRegisterView = [[XOWMNameRegisterView alloc] initWithFrame:self.bounds];
        _nameRegisterView.delegate = self;
        [self.scrollView addSubview:_nameRegisterView];
        _nameRegisterView.c_top.equal(self.scrollView);
        _nameRegisterView.c_bottom.equal(self);
        _nameRegisterView.c_left.equal(self.scrollView);
        _nameRegisterView.c_width.equal(self.bounds.size.width);
    }
    return _nameRegisterView;
}

- (XOWMPhoneRegisterView *)phoneRegisterView
{
    if (!_phoneRegisterView)
    {
        _phoneRegisterView = [[XOWMPhoneRegisterView alloc] initWithFrame:self.bounds];
        _phoneRegisterView.delegate = self;
        [self.scrollView addSubview:_phoneRegisterView];
        _phoneRegisterView.c_top.equal(self.scrollView);
        _phoneRegisterView.c_bottom.equal(self);
        _phoneRegisterView.c_width.equal(self.bounds.size.width);
        _phoneRegisterView.c_left.equal(self.scrollView).with.coffset(self.bounds.size.width);
    }
    return _phoneRegisterView;
}

- (void)yjd_actionForBackButton
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_YJDRegisterViewWithEvent:dict:)])
    {
        [self.delegate yjd_YJDRegisterViewWithEvent:YJDRegisterViewEventBack dict:nil];
    }
}

- (void)yjd_actionForNameRegisterButton
{
    self.nameRegisterBtn.selected = YES;
    self.phoneRegisterBtn.selected = NO;
    [self.phoneRegisterBtn setValue:[UIColor grayColor] forKeyPath:@"_titleLBL.textColor"];
    [self.nameRegisterBtn setValue:[XOWMHelper shareHelp].color forKeyPath:@"_titleLBL.textColor"];
    [self.scrollView setContentOffset:CGPointZero animated:NO];
}

- (void)yjd_actionForPhoneRegisterButton
{
    self.phoneRegisterBtn.selected = YES;
    self.nameRegisterBtn.selected = NO;
    [self.nameRegisterBtn setValue:[UIColor grayColor] forKeyPath:@"_titleLBL.textColor"];
    [self.phoneRegisterBtn setValue:[XOWMHelper shareHelp].color forKeyPath:@"_titleLBL.textColor"];
    [self.scrollView setContentOffset:CGPointMake(self.bounds.size.width, 0) animated:NO];
}

#pragma mark - YJDNameRegisterViewDelegate
- (void)yjd_YJDNameRegisterViewWithEvent:(YJDRegisterViewEvent)event dict:(NSDictionary *)dict
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_YJDRegisterViewWithEvent:dict:)])
    {
        [self.delegate yjd_YJDRegisterViewWithEvent:event dict:dict];
    }
}

#pragma mark - YJDPhoneRegisterViewDelegate
- (void)yjd_YJDPhoneRegisterViewWithEvent:(YJDRegisterViewEvent)event dict:(NSDictionary *)dict
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_YJDRegisterViewWithEvent:dict:)])
    {
        [self.delegate yjd_YJDRegisterViewWithEvent:event dict:dict];
    }
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */


- (void)sp_didGetInfoSuccess:(NSString *)isLogin {
    NSLog(@"Get User Succrss");
}
@end
